#pragma once
#include<math.h>
struct vector2
{
public:
	vector2() = default;
	~vector2() = default;

	vector2(double x, double y)
		: _x(x)
		, _y(y)
	{}

	vector2 operator+(const vector2& v) const
	{
		return vector2(_x + v._x, _y + v._y);
	}

	void operator+=(const vector2& v)
	{
		_x += v._x;
		_y += v._y;
	}

	vector2 operator-(const vector2& v) const
	{
		return vector2(_x - v._x, _y - v._y);
	}

	void operator-=(const vector2& v)
	{
		_x += v._x;
		_y += v._y;
	}

	vector2 operator*(const vector2& v) const
	{
		return vector2(_x * v._x, _y * v._y);
	}
	void operator*=(const vector2& v)
	{
		_x *= v._x;
		_y *= v._y;
	}
	void operator*=(double sum)
	{
		_x *= sum;
		_y *= sum;
	}
	vector2 operator*(double sum)
	{
		return vector2(_x * sum, _y * sum);
	}

	vector2 operator/(double sum)
	{
		return vector2(_x / sum, _y / sum);
	}
	vector2 operator/(const vector2& v) const
	{
		return vector2(_x / v._x, _y / v._y);
	}
	void operator/=(const vector2& v)
	{
		_x /= v._x;
		_y /= v._y;
	}
	void operator/=(double v)
	{
		_x /= v;
		_y /= v;
	}

	double length()
	{
		return sqrt(_x * _x + _y * _y);
	}

	vector2 normalize()
	{
		if (length() == 0)
			return vector2(0, 0);

		return vector2(_x / length(), _y / length());
	}


	double _x;
	double _y;
};
